package com.mall.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.mall.entity.OmsOrder;
import com.mall.entity.OmsOrderItem;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
public class FrontOrderDto {

    @ApiModelProperty("订单id")
    private Long id;

    @TableField("member_id")
    private Long memberId;

    @TableField("coupon_id")
    private Long couponId;

    @ApiModelProperty("订单编号")
    private String orderSn;

    @ApiModelProperty("提交时间")
    private Date createTime;

    @ApiModelProperty("用户帐号")
    private String memberUsername;

    @ApiModelProperty("订单总金额")
    private BigDecimal totalAmount;

    @ApiModelProperty("应付金额（实际支付金额）")
    private BigDecimal payAmount;

    @ApiModelProperty("运费金额")
    private BigDecimal freightAmount;

    @ApiModelProperty("促销优化金额（促销价、满减、阶梯价）")
    private BigDecimal promotionAmount;

    @ApiModelProperty("优惠券抵扣金额")
    private BigDecimal couponAmount;

    @ApiModelProperty("支付方式：0->未支付；1->支付宝；2->微信")
    private int payType;

    @ApiModelProperty("订单状态：0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单")
    private int status;

    @ApiModelProperty("订单类型：0->正常订单；1->秒杀订单")
    private int orderType;

    @ApiModelProperty("物流公司(配送方式)")
    private String deliveryCompany;

    @ApiModelProperty("物流单号")
    private String deliverySn;

    @ApiModelProperty("自动确认时间（天）")
    private int autoConfirmDay;

    @ApiModelProperty("活动信息")
    private String promotionInfo;

    @ApiModelProperty("收货人姓名")
    private String receiverName;

    @ApiModelProperty("收货人电话")
    private String receiverPhone;

    @ApiModelProperty("收货人邮编")
    private String receiverPostCode;

    @ApiModelProperty("省份/直辖市")
    private String receiverProvince;

    @ApiModelProperty("城市")
    private String receiverCity;

    @ApiModelProperty("区")
    private String receiverRegion;

    @ApiModelProperty("详细地址")
    private String receiverDetailAddress;

    @ApiModelProperty("订单备注")
    private String note;

    @ApiModelProperty("确认收货状态：0->未确认；1->已确认")
    private int confirmStatus;

    @ApiModelProperty("删除状态：0->未删除；1->已删除")
    private int deleteStatus;

    @ApiModelProperty("支付时间")
    private Date paymentTime;

    @ApiModelProperty("发货时间")
    private Date deliveryTime;

    @ApiModelProperty("确认收货时间")
    private Date receiveTime;

    @ApiModelProperty("评价时间")
    private Date commentTime;

    @ApiModelProperty("修改时间")
    private Date modifyTime;

    @ApiModelProperty("订单商品项")
    private List<FrontOrderItem> orderItemList;

    public void setOrder(OmsOrder order){
        //从order中取出合适的属性赋值给当前对象
        this.setId(order.getId());
        this.setMemberId(order.getMemberId());
        this.setCouponId(order.getCouponId());
        this.setOrderSn(order.getOrderSn());
        this.setCreateTime(order.getCreateTime());
        this.setMemberUsername(order.getMemberUsername());
        this.setTotalAmount(order.getTotalAmount());
        this.setPayAmount(order.getPayAmount());
        this.setFreightAmount(order.getFreightAmount());
        this.setPromotionAmount(order.getPromotionAmount());
        this.setCouponAmount(order.getCouponAmount());
        this.setPayType(order.getPayType());
        this.setStatus(order.getStatus());
        this.setOrderType(order.getOrderType());
        this.setDeliveryCompany(order.getDeliveryCompany());
        this.setDeliverySn(order.getDeliverySn());
        this.setAutoConfirmDay(order.getAutoConfirmDay());
        this.setPromotionInfo(order.getPromotionInfo());
        this.setReceiverName(order.getReceiverName());
        this.setReceiverPhone(order.getReceiverPhone());
        this.setReceiverPostCode(order.getReceiverPostCode());
        this.setReceiverProvince(order.getReceiverProvince());
        this.setReceiverCity(order.getReceiverCity());
        this.setReceiverRegion(order.getReceiverRegion());
        this.setReceiverDetailAddress(order.getReceiverDetailAddress());
        this.setNote(order.getNote());
        this.setConfirmStatus(order.getConfirmStatus());
        this.setDeleteStatus(order.getDeleteStatus());
        this.setPaymentTime(order.getPaymentTime());
        this.setDeliveryTime(order.getDeliveryTime());
        this.setReceiveTime(order.getReceiveTime());
        this.setCommentTime(order.getCommentTime());
        this.setModifyTime(order.getModifyTime());
    }

    public void setOrderItemList(List<OmsOrderItem> orderItemList){
        if(orderItemList != null && orderItemList.size() > 0){
            this.orderItemList = new ArrayList<>();
            for(OmsOrderItem orderItem : orderItemList){
                FrontOrderItem frontOrderItem = new FrontOrderItem();
                frontOrderItem.setOrderItem(orderItem);
                this.orderItemList.add(frontOrderItem);
            }
        }
    }
}
